import request from 'umi-request';

export async function getProtocolPage(params = {},type) {
  let {trainingTime, ...restParams} = params;
  let queryParams = {
    pageNum: params.current,
    pageSize: params.pageSize,
    type: type,
    ...restParams
  };
  if (trainingTime){
    queryParams.trainingStartTime = params.trainingTime[0];
    queryParams.trainingEndTime = params.trainingTime[1];
  }
  return request('/hr-ssc/api/api-admin/protocol/getProtocolPage', {
    method: 'get',
    params: queryParams,
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function saveAndUpdateProtocol(data = {}) {
  return request('/hr-ssc/api/api-admin/protocol/saveAndUpdateProtocol', {
    method: 'post',
    data: data,
  }).then(res => res);
}


export async function getProtocolPersonnel(id) {
  return request('/hr-ssc/api/api-admin/protocol/getProtocolPersonnel', {
    method: 'get',
    params: {protocolId:id},
  }).then(res => {
    if (res.flag){
      return res.data
    }
    return []
  });
}

export async function updateProtocolStatusById(id) {
  return request('/hr-ssc/api/api-admin/protocol/updateProtocolStatusById', {
    method: 'get',
    params: {id},
  }).then(res => res);
}

export async function saveProtocolInfo(ProtocolPersonnelId) {
  return request('/hr-ssc/api/api-admin/eSign/saveProtocolInfo', {
    method: 'post',
    data: {ProtocolPersonnelId},
    requestType: 'form'
  }).then(res => res);
}

export async function getContractModelList() {
  return request('/hr-ssc/api/api-admin/eSign/getContractModelList', {
    method: 'post',
    data:{
      type:5,
      kind:0
    },
    requestType: 'form'
  }).then((res) => {
    return res.data;
  });
}

export async function updateProtocolPersonnelStatusFive(data) {
  return request('/hr-ssc/api/api-admin/protocol/updateProtocolPersonnelStatusFive', {
    method: 'get',
    params: data,
  }).then(res => res);
}


